<template>
	<div class="home">
	
		<!-- charts -->
		<el-row :gutter="15" class="mt15" >
			<el-col :md="24" :lg="24" :xl="24" class="mb15">
				<el-card shadow="hover">
					<div slot="header">
						<span>今日订单情况</span>
					</div>
					<div class="charts">
						<div class="charts-right">
							<div ref="homeStockRef" class="h100"></div>
						</div>
					</div>
				</el-card>
			</el-col>
			
	
		</el-row>

	</div>
</template>

<script>
import * as echarts from 'echarts';
import Scroll from 'vue-seamless-scroll';
import { CountUp } from 'countup.js';
import { Session } from '@/utils/storage';
import { formatAxis, formatDate } from '@/utils/formatTime';
import { recommendList, chartsRightList, newsInfoList, dailyMessage } from './mock';
import axios  from 'axios';
export default {
	name: 'home',
	components: { Scroll },
	data() {
		return {
			recommendList,
			chartsRightList,
			newsInfoList,
			userInfo: {},
			dailyMessage: {},

			requesturl:"http://162.14.107.118:8086/",//axios请求地址
			nowdaynum:[{}],
			orderState:[0,0,0],//获取
		};
	},
	created() {
		this.initUserInfo();
	},
	computed: {
		currentTime() {
			return formatAxis(new Date());
		},
		optionSingleHeight() {
			return {
				singleHeight: 28,
				limitMoveNum: 8,
				waitTime: 2000,
			};
		},
		getUserInfos() {
			return this.$store.state.userInfos.userInfos;
		},
	},
	mounted() {

		//PC得到今天的订单情况
		this.getNowDayOrderState();

	},
	methods: {

		//PC获得今天的订单情况
		getNowDayOrderState(){
			axios.get(this.requesturl+"PC/CountOrderState").then(res=>{
				
				this.orderState=res.data.data
				
				const myChart = echarts.init(this.$refs.homeStockRef);
				const option = {
					grid: {
						top: 50,
						right: 20,
						bottom: 30,
						left: 30,
					},
					tooltip: {
						trigger: 'item',
					},
					legend: {
						left: 'center',
					},
					series: [
						{
							name: '订单详情',
							type: 'pie',
							radius: ['40%', '70%'],
							avoidLabelOverlap: false,
							itemStyle: {
								borderRadius: 10,
								borderColor: '#fff',
								borderWidth: 2,
							},
							data: [
								{ value: this.orderState[0], name: '顾客下单' },
								{ value: this.orderState[1], name: '商家接单' },
								{ value: this.orderState[2], name: '顾客付款' },
							],
								top: 30,
							},
						],
					};
					myChart.setOption(option);
					window.addEventListener('resize', () => {
						myChart.resize();
					});

			})
		},
		
		// 初始化登录信息
		initUserInfo() {
			if (!Session.get('userInfo')) return false;
			this.userInfo = Session.get('userInfo');
			this.userInfo.time = formatDate(new Date(this.userInfo.time), 'YYYY-mm-dd HH:MM:SS');
		},
		// 消息通知当前项点击
		onNewsInfoListClick(v) {
			window.open(v.link);
		},
	
		
	},
};
</script>

<style scoped lang="scss">
@import './index.scss';
</style>
